package com.laow.action;

import com.laow.entity.EbookCategory;
import com.laow.entity.EbookEntry;
import com.laow.entity.Page;
import com.laow.service.EbookService;
import com.laow.utils.PageUtils;
import com.opensymphony.xwork2.ActionSupport;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.stereotype.Controller;

import java.util.List;

@Controller
public class EbookAction extends ActionSupport {

    @Autowired
    @Qualifier("ebookServiceImpl")
    private EbookService ebookService;

    private int everyPage=4;    // 每页显示的数据

    private int categoryId=0;      // 下拉列表的id

    private int currentPage = 0;// 当前页码

    private Page page;     // 分页数据

    private List<EbookEntry> ebookEntries;    // 图书所有信息

    private List<EbookCategory> categorys;    // 下拉列表的数据


    public String defauEbookData() throws Exception{
        if (ebookEntries==null){
            ebookEntries = ebookService.ebookEntrys(categoryId, currentPage);
        }
        int tote = ebookService.selEbookEntryDataCount(categoryId);
        page = PageUtils.getPage(everyPage, tote, currentPage);

        // 查询下拉列表的数据
        categorys = ebookService.getCategorys();
        return "success";
    }

    public String ajEbookData() throws Exception{
        ebookEntries = ebookService.ebookEntrys(categoryId, currentPage);
        int tote = ebookService.selEbookEntryDataCount(categoryId);
        page = PageUtils.getPage(everyPage, tote, currentPage);
        return "success";
    }


    public List<EbookCategory> getCategorys() {
        return categorys;
    }

    public void setCategorys(List<EbookCategory> categorys) {
        this.categorys = categorys;
    }

    public int getCategoryId() {
        return categoryId;
    }

    public void setCategoryId(int categoryId) {
        this.categoryId = categoryId;
    }

    public int getCurrentPage() {
        return currentPage;
    }

    public void setCurrentPage(int currentPage) {
        this.currentPage = currentPage;
    }

    public Page getPage() {
        return page;
    }

    public void setPage(Page page) {
        this.page = page;
    }

    public List<EbookEntry> getEbookEntries() {
        return ebookEntries;
    }

    public void setEbookEntries(List<EbookEntry> ebookEntries) {
        this.ebookEntries = ebookEntries;
    }
}
